package com.jb.web.bean.inspector;

import com.jb.web.application.Wizard;

import com.jb.web.bean.UIComponentImpl;
import com.jb.web.bean.event.UIEvent;
import com.jb.web.context.WebContext;
import com.jb.web.model.GUID;

import java.util.Enumeration;

public class GeneralWizard extends Wizard {
    private void setPropertiesValue(WebContext ctx, 
                                    UIComponentImpl component) {
        //WebBeanz wb = component;
        Enumeration hm = ctx.getRequest().getParameterNames();
        while (hm.hasMoreElements()) {
            String pName = (String)hm.nextElement();
            try {
                String pValue = ctx.getRequest().getParameter(pName);
                component.setPropertyValue(pName, pValue);
            } catch (Exception e) {
                //
            }
        }
    }

    public void create(WebContext ctx, UIEvent event) {
        super.create(ctx, event);
        UIComponentImpl dr = 
            (UIComponentImpl)this.getObject(); //created, we need to set
        if (dr == null) {
            ctx.addErrorMessage(this, "Failed to get object while creating");
        } else
            this.setPropertiesValue(ctx, dr);
        if (dr.getClientId() == null || dr.getClientId().length() == 0)
            dr.setClientId(GUID.getInstance().getNext());

        dr.setValue(dr.getClientId());
        ctx.getSession().setSelected(dr);
    }

}
